sqr = list()
used = []

for i in range(9):
    used.append(False)

def solve(n):
    if (n == 8):
        if (sqr[1] + sqr[4] + sqr[7] != 15):
            return

    if (n == 9):
        if (sqr[6] + sqr[7] + sqr[8] != 15):
            return

        if (sqr[2] + sqr[5] + sqr[8] != 15):
            return

        if (sqr[0] + sqr[4] + sqr[8] != 15):
            return

        print(sqr)
        return

    if (n == 3):
        if (sqr[0] + sqr[1] + sqr[2] != 15):
            return

    if (n == 6):
        if (sqr[3] + sqr[4] + sqr[5] != 15):
            return

    if (n == 7):
        if (sqr[0] + sqr[3] + sqr[6] != 15):
            return

        if (sqr[2] + sqr[4] + sqr[6] != 15):
            return

    for i in range(9):
        if (used[i]):
            continue

        sqr.append(i+1)
        used[i] = True
        solve(n+1)
        used[i] = False
        sqr.pop()

solve(0)
